﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.BaseQueryModel;
using ZBJF.Warranty.Model.ViewModel.InsuranceProducts;

namespace ZBJF.Warranty.BLL
{
     public partial class InsuranceProductScreenSPsService
     {
         //public bool IsExist(int tid, int yid, long id = 0)
         //{
         //    var expressionWhere = PredicateExtensions.True<InsuranceProductScreenSPs>();
         //    if (tid > 0)
         //        expressionWhere = expressionWhere.And(o => o.InsuranceProductId.Equals(tid) && o.AccessoriesTypeID.Equals(yid));
         //    if (id != 0)
         //        expressionWhere = expressionWhere.And(o => o.ID != id);
         //    return LoadEntities(expressionWhere).Any();
         //}
         public IQueryable<InsuranceProductScreenSPs> GetInsuranceProductScreenSPsAll(int cellPhoneServiceProjectID)
         {
             return LoadEntities(o => o.CellPhoneServiceProjectID == cellPhoneServiceProjectID);
         }
         /// <summary>
         /// 获取服务项目下的可用屏幕
         /// </summary>
         /// <param name="cellPhoneServiceProjectIDs"></param>
         /// <returns></returns>
         public IQueryable<InsuranceProductScreenSPs> GetInsuranceProductScreenSPsList(
             List<int> cellPhoneServiceProjectIDs)
         {
             return LoadEntities(o => cellPhoneServiceProjectIDs.Contains(o.CellPhoneServiceProjectID));
         }
         

        #region 获取保险产品配件等级，配件类型等信息 + List<AccessoriesLevelList> GetAccessoriesLevelList(int cellPhoneServiceProjectID) 
        /// <summary>
        /// 获取保险产品配件等级，配件类型等信息
        /// </summary>
        /// <param name="cellPhoneServiceProjectID"></param>
        /// <returns></returns>
        public List<AccessoriesLevelList> GetAccessoriesLevelList(int cellPhoneServiceProjectID)
        {
            return (from a in LoadEntities(t => t.CellPhoneServiceProjectID == cellPhoneServiceProjectID)
                    join b in ServiceFactory.AccessoriesLevelServiceInstance.LoadEntities(t => true) on a.AccessoriesLevelID equals b.ID
                    join c in ServiceFactory.AccessoriesTypeServiceInstance.LoadEntities(t => true) on a.AccessoriesTypeID equals c.ID
                    select new AccessoriesLevelList
                    {
                        ID = a.ID,
                        AccessoriesLevelID = a.AccessoriesLevelID,
                        AccessoriesLevelName = b.AccessoriesLevelName,
                        AccessoriesTypeID = a.AccessoriesTypeID,
                        AccessoriesTypeName = c.AccessoriesName,
                        CellPhoneServiceProjectID = a.CellPhoneServiceProjectID,
                        ProductTypeID = a.ProductTypeID,
                    }).ToList();
        }
    #endregion
    }
}
